package io.yunho.webflux.client.controller;

import io.yunho.webflux.client.domain.User;
import io.yunho.webflux.client.service.IUser;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;

/**
 * @author: yunho
 * @date: 2021/5/14 18:29
 * @description:
 */
@RestController
public class TestController {
    @Resource
    IUser userApi;
    @GetMapping("/")
    public void test(){
        //不订阅，不会实际发出请求，但是会进入我们的代理类
//        userApi.getAllUser();;
//        userApi.getUserById("11111");
//        userApi.deleteUser("123123123");
//        userApi.putUser(Mono.just(User.builder().name("andy").age(22).build()));

//        Flux<User> allUser = userApi.getAllUser();
//        allUser.subscribe(System.out::println);
        String id = "609c8b91b226274ee25cb809";
        userApi.getUserById(id).subscribe(
                u -> System.out.println("get user:\t"+u)
        ,ex->System.err.println("找不到用户："+ex.getMessage()));
//        userApi.deleteUser(id).subscribe();
//        userApi.putUser(Mono.just(User.builder().age(23).name("jj").build()))
//                  .subscribe(System.out::println);
    }

}
